Fix filtering for test deps
authorAlex Crichton <alex@alexcrichton.com>
Thu, 10 Jul 2014 18:50:03 +0000 (11:50 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 10 Jul 2014 18:50:03 +0000 (11:50 -0700)
This fixes `cargo test` to only test the *local* package

src/cargo/ops/cargo_rustc.rs
tests/test_cargo_test.rs

index ff7aa6a3f681a7f3849fb9621a691e5f5bbd9d47..d8be4f11ab3bdbe860e91e131f4ca211846e232d 100644 (file)
@@ -105,7 +105,10 @@ pub fn compile_targets<'a>(env: &str, targets: &[&Target], pkg: &Package,
 
         // Only compile lib targets for dependencies
         let targets = dep.get_targets().iter().filter(|target| {
-            target.is_lib() && target.get_profile().get_env() == env
+            target.is_lib() && match env {
+                "test" => target.get_profile().is_compile(),
+                _ => target.get_profile().get_env() == env,
+            }
         }).collect::<Vec<&Target>>();
 
         jobs.push((dep, try!(compile(targets.as_slice(), dep, &mut cx))));
@@ -121,7 +124,7 @@ pub fn compile_targets<'a>(env: &str, targets: &[&Target], pkg: &Package,
 
 fn compile(targets: &[&Target], pkg: &Package,
            cx: &mut Context) -> CargoResult<(Freshness, Job)> {
-    debug!("compile_pkg; pkg={}; targets={}", pkg, pkg.get_targets());
+    debug!("compile_pkg; pkg={}; targets={}", pkg, targets);
 
     if targets.is_empty() {
         return Ok((Fresh, proc() Ok(())))
index 07a9f0e4f2fe921c1d7b59538ad9f1be91de1fe2..77f90feb5e9e2d98c8aa08935ce24b2b040e2eb0 100644 (file)
@@ -57,27 +57,49 @@ test!(test_with_lib_dep {
 })
 
 test!(test_with_deep_lib_dep {
-    let p = project("foo")
+    let p = project("bar")
         .file("Cargo.toml", r#"
-            [project]
+            [package]
             name = "bar"
             version = "0.0.1"
             authors = []
 
             [dependencies.foo]
-            path = "foo"
+            path = "../foo"
         "#)
         .file("src/lib.rs", "
             extern crate foo;
-            pub fn bar() {}
-        ")
+            #[test]
+            fn bar_test() {
+                foo::foo();
+            }
+        ");
+    let p2 = project("foo")
         .file("Cargo.toml", r#"
-            [project]
+            [package]
             name = "foo"
             version = "0.0.1"
             authors = []
         "#)
-        .file("src/lib.rs", "");
+        .file("src/lib.rs", "
+            pub fn foo() {}
 
-    assert_that(p.cargo_process("cargo-test"), execs().with_status(0));
+            #[test]
+            fn foo_test() {}
+        ");
+
+    p2.build();
+    assert_that(p.cargo_process("cargo-test"),
+                execs().with_status(0)
+                       .with_stdout(format!("\
+{compiling} foo v0.0.1 (file:{dir})
+{compiling} bar v0.0.1 (file:{dir})
+
+running 1 test
+test bar_test ... ok
+
+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured\n\n\
+                       ",
+                       compiling = COMPILING,
+                       dir = p.root().display()).as_slice()));
 })